﻿Imports MeoTom.Core.BLL
Imports MeoTom.Core

Partial Public Class ArticleTag
    Inherits UI.Page
    Private ReadOnly _tag As New Tags()
    Private ReadOnly _util2 As New Utilities.Common()

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim previousPage As String = ""
        If Request.QueryString.ToString = vbNullString Then
            previousPage = Server.UrlEncode(Request.ServerVariables("PATH_INFO"))
        Else
            previousPage = Server.UrlEncode(Request.ServerVariables("PATH_INFO") & "?" & Request.QueryString.ToString())
        End If
        _util2.ValidateLogin(previousPage)

        BindGrid()
    End Sub

    Public Sub BindGrid()
        Select Case Request.QueryString("message")
            Case "3"
                lblError.Attributes.Remove("style")
                lblError.InnerHtml = "* Tag updated."
            Case "5"
                lblError.Attributes.Remove("style")
                lblError.InnerHtml = "* Tag not updated."
        End Select

        grvListArticleTag.DataSource = _tag.GetAll()
        grvListArticleTag.DataBind()

        popularTags.InnerHtml = _tag.GetDefaultTag(1)
    End Sub

    Private Sub btnApply_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnApply.Click
        For Each s As String In Regex.Split(Request.Form("cboCheck"), ",")
            _tag.TagID = Integer.Parse(s)
            _tag.Delete()
        Next
        _tag.GetDefaultTag(0)
        Response.Redirect("/mt-inside/ArticleTag.aspx", False)
    End Sub

    Private Sub btnApply2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnApply2.Click
        btnApply_Click(sender, e)
    End Sub

    Private Sub grvListArticleTag_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles grvListArticleTag.PageIndexChanging
        grvListArticleTag.PageIndex = e.NewPageIndex
        BindGrid()
    End Sub
End Class